package week10;

import java.util.Scanner;

class ArrayUtils{
	public static double findMax(double[] arr,int begin, int end) throws IllegalArgumentException{
		if(begin>=end){
			IllegalArgumentException e=new IllegalArgumentException("begin:"+begin+" >= end:"+end);
			throw e;
		}
		if(begin<0){
			IllegalArgumentException e=new IllegalArgumentException("begin:"+begin+" < 0");
			throw e;
		}
		if(end>arr.length){
			IllegalArgumentException e=new IllegalArgumentException("end:"+end+" > arr.length");
			throw e;
		}
		double temp=arr[begin];
		for(int i=begin;i<end;i++){
			if(temp<arr[i]){
				temp=arr[i];
			}
		}
		return temp;
	}
}

public class Main3 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in 

);
		int n=sc.nextInt();
		ArrayUtils arr=new ArrayUtils();
		double[] arr1=new double[n];
		for(int i=0;i<n;i++){
			arr1[i]=sc.nextInt();
		}
		while(sc.hasNextInt()){
			 try{
	                int begin = sc.nextInt();
	                int end = sc.nextInt();
	                System.out.println(ArrayUtils.findMax(arr1,begin,end));
	            }catch(IllegalArgumentException e){
	                System.out.println(e);
	            }	
		}
		try {
				System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
			} catch (Exception e1) {
			} 
		
	}

}

